<template>
  <div>
    <lb-title></lb-title>
    <div class="page-main">
      <el-form
        @submit.native.prevent
        :model="defaultForm"
        :rules="defaultFormRules"
        ref="defaultForm"
        label-width="110px"
      >
        <el-form-item label="名片数量" prop="card_number">
          <el-input-number
            class="lb-input-number"
            :controls="false"
            v-model="defaultForm.card_number"
          ></el-input-number>
          <lb-tool-tips
            tips="填写了此项参数后，新建的小程序的创建名片数量将采用此项设置"
          ></lb-tool-tips>
        </el-form-item>
        <el-form-item label="群发通知" prop="send_switch">
          <el-radio-group v-model="defaultForm.send_switch">
            <el-radio :label="0">{{ $t('action.OFF') }}</el-radio>
            <el-radio :label="1">{{ $t('action.ON') }}</el-radio>
          </el-radio-group>
          <lb-tool-tips
            tips="填写了此项参数后，新建的小程序的能否使用群发短信功能将采用此项设置"
          ></lb-tool-tips>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitFormInfo('defaultForm')">{{
            $t('action.submit')
          }}</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      defaultForm: {
        card_number: '',
        send_switch: ''
      },
      defaultFormRules: {
        card_number: { required: true, type: 'number', message: '请输入数量', trigger: 'blur' },
        send_switch: { required: true, type: 'number', message: '请选择', trigger: 'change' }
      }
    }
  },
  created () {
    this.getFormInfo()
  },
  methods: {
    submitFormInfo (name) {
      this.$refs[name].validate(valid => {
        if (valid) {
          let { defaultForm } = this
          this.$api.submitDefaultFormInfo(defaultForm).then(res => {
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successSub'))
            }
          })
        }
      })
    },
    getFormInfo () {
      this.$api.getDefaultFormInfo().then(res => {
        if (res.code === 200) {
          for (let key in this.defaultForm) {
            this.defaultForm[key] = res.data[key]
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
